<template>
	<view class="">
		<view class="user-content">
			<view class="user">
				<view class="">
					<u-avatar :src="userInfo.avatar" size="65"></u-avatar>
				</view>
				<view class="user-info">
					<view class="">
						ID:{{userInfo.id}}
					</view>
					<view class="">
						{{userInfo.nickname}}
					</view>
					<view class="" style="color: #999;font-size: 24rpx;">
						 {{userInfo.level != 0 ? '已享受会员权益': '开通会员享受更多特权'}}
					</view>
				</view>
			</view>
		<!-- 	<view class="" style="margin-top: 30rpx;text-align: right;" @click="wxShare()">
				分享
			</view> -->
		</view>
		<view class="menu">
			<view class="menu-item" v-for="(item,index) in navList"  @click="nav(item.page)">
				<view style="display: flex;flex-direction: row;align-items: center;">
					<u-image :src="`/static/img/nav-${index + 1}.png`" width="35px" height="35px" shape="circle">
					</u-image>
					<view class="" style="font-size: 32rpx;margin-left: 10rpx;">
						{{item.name}}
					</view>
				</view>
				<view class="value" v-if="item.value">
					{{item.value}}
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import wx from '@/common/jweixin-module.js'
	import {
		getUserInfo
	} from '@/common/api.js'
	
	export default {
		data() {
			return {
				navList: [{
						name: "查询次数",
						// page:'/pages/mine/vip'
						value:""

					},{
						name: "开通会员",
						page:'/pages/mine/vip'
					},
					{
						name: "关于我们",
						page:'/pages/about/idnex'

					}
				]

			}
		},
		computed: {
			userInfo() {
				return this.$store.state.$userInfo
			}
		},
		onShow() {
			getUserInfo().then(res => {
				console.log(res);
				this.$store.state.$userInfo = res.userinfo;
				uni.setStorageSync('token', res.userinfo.token);
				uni.setStorageSync('userinfo', res.userinfo);
				this.navList[0].value = this.userInfo.level != 0 ? '无限次数' : res.user_find_num
			})
		},
		onLoad() {
			//获取微信公众号的配置
			uni.request({
				url: 'http://chatadmin.baimajingxuan.com/api/login/wechatJssdk',
				data: {
					url: location.href.split('#')[0]
				},
				method: 'POST',
				success: res => {
					console.log('res1111', res.data.data);
					var s = res.data;
					wx.config({
						debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
						appId: s.data.appId, // 必填，公众号的唯一标识
						timestamp: s.data.timestamp, // 必填，生成签名的时间戳
						nonceStr: s.data.noncestr, // 必填，生成签名的随机串
						signature: s.data.signature.toLowerCase(), // 必填，签名，见附录1
						jsApiList: [
							"updateTimelineShareData","updateAppMessageShareData"
						]
					});
					if (typeof callback === 'function') {
						callback(res.data);
					}
					wx.ready(() => {
						wx.checkJsApi({
							// 需要检测的JS接口列表
							jsApiList: ['chooseImage'],
							success: function(res) {
								
							}
						});
					})
				},
				fail: err => {
					
				}
			});
		},
		methods: {
			nav(url) {
				uni.navigateTo({
					url
				})
			},
			wxShare() {
				let _this = this;
				wx.ready(function() { //需在用户可能点击分享按钮前就先调用
					wx.updateAppMessageShareData({
						title: '分享标题', // 分享标题
						desc: '分享邀请', // 分享描述
						link: location.href+'user_id=1', // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
						imgUrl: "http://chatadmin.baimajingxuan.com/assets/img/qrcode.png", // 分享图标，这个必须要写https，不然会提示
						success: function() {
							// 设置成功
						}
					})
				});
			}
		}
	}
</script>

<style>
	.user-content {
		background-color: #fff;
		padding: 30rpx;
		border-bottom-left-radius: 30rpx;
		border-bottom-right-radius: 30rpx;
	},
	.user {
		display: flex;
		flex-direction: row;
	}

	.user-info {
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		margin-left: 20rpx;
		color: #999;
		font-size: 32rpx;
	}

	.menu {
		padding: 30rpx;
	}

	.menu-item {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
		background-color: #fff;
		border-radius: 30rpx;
		margin-top: 30rpx;
		padding: 30rpx;
	}
	
	.value {
		font-size: 24rpx;
		color: #5983F3;
	}
</style>
